﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DONGACS.Assembler;
using DONGACS.DAO;
using DONGACS.Domain;
using DONGACS.DTO;
using System.Transactions;


namespace DONGACS.SERVICE
{
    public class PermissionsAllUsersService
    {
        PermissionsAllUsersAssembler PermissionsAllUsersAssembler = new PermissionsAllUsersAssembler();
        PermissionsAllUsersDao PermissionsAllUsersDao = new PermissionsAllUsersDao();


        public IList<PermissionsAllUsersDto> GetAllPermissionsAllUsers()
        {
            IList<PermissionsAllUsers> permissionsAllUsersList = PermissionsAllUsersDao.GetAllPermissionsAllUsers();

            IList<PermissionsAllUsersDto> permissionsAllUsersDtoList = PermissionsAllUsersAssembler.ConvertToDataTransferObjectList(permissionsAllUsersList);

            return permissionsAllUsersDtoList;
        }

        // 
        public bool DeleteAllPermissionsAllUsers()
        {
           return PermissionsAllUsersDao.DeleteAllPermissionsAllUsers();
        }

        public bool DeleteAllPermissionAllUsersByListPathsId(IList<int> listPathID)
        {
            return PermissionsAllUsersDao.DeleteAllPermissionAllUsersByListPathsId(listPathID);
        }

        public bool AddNewPermissionsAllUsers(PermissionsAllUsersDto permissionsAllUsersDto)
        {
            return  PermissionsAllUsersDao.AddNewPermissionsAllUsers(PermissionsAllUsersAssembler.ConvertToBusinessObject(permissionsAllUsersDto));
        }

        //[Transaction] : Cần thiết
        public void UpdatePermissionsForAllUsers(IList<PermissionsAllUsersDto> permissionsAllUsersDtos)
        {
            ////delete all permission for all user
            this.PermissionsAllUsersDao.DeleteAllPermissionsAllUsers();

            ////update new setting
            foreach (var dto in permissionsAllUsersDtos)
            {
                this.PermissionsAllUsersDao.AddNewPermissionsAllUsers(
                    this.PermissionsAllUsersAssembler.ConvertToBusinessObject(dto));
            }
        }

    }
}
